package com.yupi.springbootinit.rpc.IMPL;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.jun.apiplatformcommon.entity.User;
import com.jun.apiplatformcommon.service.InnerUserService;
import com.yupi.springbootinit.common.ErrorCode;
import com.yupi.springbootinit.exception.BusinessException;
import com.yupi.springbootinit.mapper.UserMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;

import javax.annotation.Resource;

@DubboService
public class InnerUserServiceImpl implements InnerUserService {

	@Resource
	private UserMapper userMapper;

	@Override
	public User getInvokeUser(String accessKey) {
		if (StrUtil.isBlank(accessKey)) {
			throw new BusinessException(ErrorCode.PARAMS_ERROR);
		}
		LambdaQueryWrapper<com.yupi.springbootinit.model.entity.User> lambdaQueryWrapper = new LambdaQueryWrapper<>();
		lambdaQueryWrapper.eq(com.yupi.springbootinit.model.entity.User::getAccessKey, accessKey);
		com.yupi.springbootinit.model.entity.User user = userMapper.selectOne(lambdaQueryWrapper);
		if (user == null) {
			throw new BusinessException(ErrorCode.NOT_FOUND_ERROR);
		}
		User user1 = new User();
		BeanUtils.copyProperties(user, user1);
		return user1;
	}
}